#! /bin/bash

# installs original systemc-2.2.0 to '$SYSCPAR_ROOT/tools/automake-1.6.3'
# requires:
#	 $SYSCPAR_ROOT/downloads/automake-1.6.3.tar.gz
#	 $SYSCPAR_ROOT/downloads/systemc-2.2.0.tgz
#
# tested with g++ ver. 4.4.3
# you'll probably get a lot of warnings, it's ok
#
# type --help for usage

usage="$0 --help \t\t - shows this\n$0\t\t\t - installs original systemc-2.2.0\n$0 --clean\t\t - removes original systemc-2.2.0 installed by this script"

case $1 in '-h'|'-help'|'--help')
	echo  -e $usage
	exit;;
esac

[[ $1 == "--clean" ]] && { rm -rf $SYSCPAR_ROOT/code/orig/ $SYSCPAR_ROOT/tools/automake-1.6.3; echo 'cleaned'; exit 0; }

#unpack & install automake
$SYSCPAR_ROOT/scripts/iautomake.sh

#unpack original systemc
mkdir -p $SYSCPAR_ROOT/code/orig/
cd $SYSCPAR_ROOT/code/orig
cp $SYSCPAR_ROOT/downloads/systemc-2.2.0.tgz ./
tar -xzf ./systemc-2.2.0.tgz
rm -f ./systemc-2.2.0.tgz


#install original systemc (debug version)
cd ./systemc-2.2.0

#fix the code
sed -i 's|^#include "sysc/utils/sc_report.h"|#include "sysc/utils/sc_report.h"\n#include <cstdlib>\n#include <cstring>\n|' ./src/sysc/utils/sc_utils_ids.cpp
sed -i 's|	$(MAKE) all CXXFLAGS="$(EXTRA_CXXFLAGS) $(DEBUG_CXXFLAGS)"|	$(MAKE) all CXXFLAGS="$(EXTRA_CXXFLAGS) $(DEBUG_CXXFLAGS) -Wno-parentheses"|' ./Makefile.am

$SYSCPAR_ROOT/scripts/1st_build.sh orig
expected_passed=`echo -e '\n' | make -C ./objdir check | grep 'PASS' | wc -l`
if [[ $expected_passed == 17 ]]
then
	echo -e '\E[32;47mOriginal systemc-2.2.0 has been installed, example suite passed ok'; tput sgr0
else
	echo -e '\E[31;47mSomething went wrong during the installation, try installing manualy'; tput sgr0
	rm -rf $SYSCPAR_ROOT/code/orig/ $SYSCPAR_ROOT/tools/automake-1.6.3
fi





